﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Badger.Vhdl;
using Weazel.Badger.Vhdl.Statements;

#endregion

namespace Weazel.Badger
{
  public abstract class RegisterSignal : Vhdl.Signal
  {
    /// <summary>
    /// The parent register of this read signal
    /// </summary>
    protected VhdlRegister register;
    public VhdlRegister Register
    {
      get
      {
        return register;
      }
    }
    public RegisterSignal(VhdlRegister register, string name) : 
      base(register.Type, register.GezelType, name)
    {
      this.register = register;
      this.Type = register.Type;
    }
  }

  public class RegisterReadSignal : RegisterSignal
  {
    /// <summary>
    /// 
    /// </summary>
    /// <param name="stmt"></param>
    public override void AddAssignmentStatement(Weazel.Badger.Vhdl.Statements.SignalAssignmentStatement stmt)
    {
      register.WriteSignal.AddAssignmentStatement(stmt);
    }

    public override Weazel.Badger.Vhdl.Types.TypeSet GetPossibleTypes()
    {
      // only one possible type
      return new Weazel.Badger.Vhdl.Types.TypeSet(register.Type);
    }

		public override void SetActualType(Entity entity, Process process, StatementCollection statements, Weazel.Badger.Vhdl.Types.Type type)
    {
      if (!type.Compare(register.Type))
      {
        string message =
          "SetActualType(): Unusable type";

        throw new NotSupportedException(message);
      }
    }

    public RegisterReadSignal(VhdlRegister register) : base(register, register.Name)
    {
    }
  }
}
